<template>
  <div class="page-login">
    <div class="box">
      <div class="logo">
        <img src="../assets/logo.png" alt="Logo" />
      </div>

      <p class="desc">明德后台权限管理系统</p>

      <div class="form">
        <el-form label-position="top" class="form">
          <el-form-item label="用户名">
            <input
              v-model="userinfo.name"
              placeholder="请输入用户名"
              maxlength="20"
              type="text"
              autocomplete="off"
            />
          </el-form-item>

          <el-form-item label="密码">
            <input
              v-model="userinfo.password"
              type="password"
              placeholder="请输入密码"
              maxlength="20"
              autocomplete="off"
            />
          </el-form-item>

          <div class="op">
            <el-button
              @click="tologin"
              style="background-color: #242733"
              type="primary"
              >登录</el-button
            >
          </div>
        </el-form>
      </div>
    </div>

    <div class="bg">
      <svgicon
        style="width: 100vw; height: 100vh"
        color="#141723"
        iconClass="bg"
      ></svgicon>
    </div>
  </div>
</template>

<script>
import { loginApi } from '../api/login';
export default {
  data() {
    return {
      userinfo: {
        name: '刘华',
        password: 'qwe',
      },
    };
  },

  methods: {
    async tologin() {
      let result = await loginApi(this.userinfo);

      if (result.code == 2000) {
        localStorage.setItem('userinfo', JSON.stringify(result.userinfo)); // 本地存储 5m
        // this.$store.state.userinfo = result.userinfo
        this.$store.commit('CHANGE_USERINFO', result.userinfo);
        localStorage.setItem('token', result.token); // value  只能存字符串
        //  发生请求
        await this.$store.dispatch('getmens');
        this.$router.push({ name: 'home' });
      } else {
        alert('账号密码错误');
      }
    },
  },
};
</script>

<style lang="scss" scoped>
$color: #2c3142;

.page-login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  position: relative;
  background-color: #fff;
  color: $color;

  .bg {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 90%;
    pointer-events: none;
    transform: rotate(180deg) scaleY(-1);

    .cl-svg {
      height: 100%;
      width: 100%;
      fill: $color;
    }
  }

  .copyright {
    position: absolute;
    bottom: 15px;
    left: 0;
    text-align: center;
    width: 100%;
    color: #666;
    font-size: 30px;
  }

  .box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    overflow: hidden;
    width: 50%;
    position: absolute;
    right: 0;
    top: 0;
    z-index: 9;

    .logo {
      height: 100px;
      margin-bottom: 20px;
      display: flex;
      align-items: center;

      img {
        height: 100px;
        background-color: $color;
        border-radius: 50px;
        border: 3px solid $color;
        margin-right: 10px;
      }

      span {
        display: inline-block;
        font-size: 38px;
        font-weight: bold;
        line-height: 1;
        letter-spacing: 3px;

        &:nth-child(6) {
          animation: dou 1s infinite linear;
        }
      }
    }

    .desc {
      font-size: 30px;
      letter-spacing: 1px;
      margin-bottom: 50px;
    }

    .form {
      width: 500px;

      :deep(.el-form) {
        .el-form-item {
          margin-bottom: 20px;
        }

        .el-form-item__label {
          padding-left: 5px;
          font-size: 20px;
        }

        input {
          height: 45px;
          width: 100%;
          box-sizing: border-box;
          font-size: 30px;
          border: 0;
          border-radius: 0;
          background-color: #f8f8f8;
          padding: 0 15px;
          border-radius: 6px;
          position: relative;

          &:-webkit-autofill {
            box-shadow: none;
            -webkit-box-shadow: 0 0 0 1000px #f8f8f8 inset;
            box-shadow: 0 0 0 1000px #f8f8f8 inset;
          }

          &::placeholder {
            font-size: 20px;
          }
        }

        .row {
          display: flex;
          align-items: center;
          width: 100%;
          position: relative;

          .pic-captcha {
            position: absolute;
            right: 0;
            top: 0;
          }
        }
      }
    }

    .op {
      display: flex;
      justify-content: center;
      margin-top: 40px;

      :deep(.el-button) {
        height: 72px;
        width: 100%;
        font-size: 24px;
        border-radius: 6px;
        letter-spacing: 1px;
      }
    }
  }
}

@media screen and (max-width: 1024px) {
  .page-login {
    .box {
      width: 100%;
    }
  }
}
</style>
